package com.qf.grabtickets.mqlisten;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.qf.entity.Coupon;
import com.qf.entity.User;
import com.qf.entity.UserCou;
import com.qf.grabtickets.mapper.TUserCouMapper;
import com.qf.grabtickets.service.ITUserCouService;
import com.qf.grabtickets.service.ITUserService;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @version 1.0
 * @Author liujinchi
 * @Date 2023/3/11 13:24
 * @注释
 */
@Component
public class SQLCus {

    @Autowired
    ITUserService service;
    @Autowired
    TUserCouMapper userCouService;
    @Autowired
    TUserCouMapper tUserCouMapper;
    @RabbitListener(queues = "queueSQL")
    public void updateSQL(Map map){

        User user = (User) map.get("user");

        Coupon coupon = (Coupon) map.get("tickets");

        service.update(new UpdateWrapper<User>().eq("id",user.getId()).set("status",1));
        //TODO 空指针
        UserCou userCou = new UserCou(null, user.getId(), coupon.getId());

        userCouService.insertByentity(userCou);

        tUserCouMapper.updateByCID(coupon.getId());
    }
}
